Detailed description of Python self-built logging module and python self-built logging Module
Easy to use
At first, we used the shortest code to experience the basic functions of logging.
Import logginglogger = logging. getLogger
The python module learns logging and the python module logging.
1. Simply print logs to the screen
Import logginglogging. debug ('this is debug message') logging.info ('this is info message') logging. warning ('this is warning message'): WARNING: root: This is warning messag
Python logging module instance and improvement, python logging instance
Python prints all attribute values of an object:
def prn_obj(obj): print '\n'.join(['%s:%s' % item for item in obj.__dict__.items()])
Python logger object at
This article mainly introduces the Python logging module logging. This article describes Logger, Handler, Formatter, log configuration management, and file configuration management logs, you can refer to the following four logging modules: loggers, handlers, filters, and formatters.
● Loggers: interfaces called By App
This article mainly introduces the benefits of using the logging module in Python to replace print. The main purpose is the simple guide of the logging module. for details about how to use the logging module, refer
Replace print? Print what's wrong?
Print may be the first thing that anyone who learns the
This article introduces the logging module-level functions of the python log module.
Logging. getLogger ([name]): returns a logger object. If no name is specified, the root logger is returned.
Logging. debug (), logging.info (), logging. warning (),
Replace print? What's wrong with print?
Print is probably the first thing that anyone who learns the Python language touches. Its main function is to print a piece of information to the console, like this:
Copy Code code as follows:
print ' Hello, logging! '
Print is also the most people used to debug their own program with the most things, like writing JS using Console.log as nat
The shell record log, eyeful flower of the redirect in line with, looked very uncomfortable there is no! I like Python, just like the feeling of buying a flashlight and a spare battery ready. Logging module is very simple, import module, define the log format. The log can be recorded in the Code through Logging.info (), logging.warning (), Logging.debug (). And immediately feel the whole person a lot better
#!/usr/bin/env python#-*-coding:utf-8-*-" "the log class can output different levels of logs to different log files" "ImportOSImportSYSImport TimeImportLoggingImportinspecthandlers= {logging. NOTSET:"/tmp/tnlog-notset.log", logging. DEBUG:"/tmp/tnlog-debug.log", Logging.info:"/tmp/tnlog-info.log",
# ! /Usr/bin/ENV Python # -*-Coding: UTF-8 -*- ''' This log class can output logs of different levels to different log files. ''' Import OS Import Sys Import Time Import Logging Import Inspecthandlers = {Logging. notset: " // Tmp/TNLOG-notset.log " , Logging
and how to output it.
There are many important levels to choose from, Debug, info, warning, error, and critical. By giving logger or handler different levels, you can output only error messages to a particular record file, or only debug information when debugging. Let's change the logger level to DEBUG and look at the output:
Logging.basicconfig (level=logging.
Python built-in Log Module logging Usage Details, pythonlogging
Introduction to the logging Module
The logging module of Python provides a common log system for third-party modules or applications. This module provides different log leve
Logging Module Introduction
Python's logging module provides a common logging system that can be easily used by Third-party modules or applications. This module provides different log levels and can record logs in different ways, such as files, HTTP get/post,smtp,socket, etc., and can even implement specific
Logging in Python
This article mainly introduces the logging module logging in Python, including the Log Level in Python and the use of common methods in the module. For more information, see
Many applications have log modules, wh
Logging Module Introduction
Python's logging module provides a common logging system that can be easily used by third-party modules or applications. This module provides different log levels and can record logs in different ways, such as files, HTTP get/post,smtp,socket, etc., and can even implement specific
Learn a new technique or language, we must first learn how to adapt to this new technology, which in the adaptation process, we have to learn how to debug the program and play the corresponding log information, is called "as long as the log is good, no bugs can not solve", in our well-known information technology, The Log4xxx series, as well as the Android.util.Log packages for Android apps, are all for developers to get a better log information service. In the language of
information ')Logger. Error ('error information ')Logger. Critical ('critical error information ')
The above code outputs five error messages on the console. There are five levels from low to high, from debug to critical. In addition, we also specify the program output level. Only information above the info level will be output.
Core log components of Python:
1. "logger ". Each program obtains a logger be
Many programmers have the need to log, and the log contains information that has normal program access logs, there may be errors, warnings and other information output, Python logging module provides a standard log interface, you can store a variety of logs through it, you can store various forms of log , the logging log can be divided into five
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.